package org.basic;

import io.netty.bootstrap.Bootstrap;
import io.netty.channel.*;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioSocketChannel;

/**
 * @author wind
 * @create 2025-01-16 11:04
 */
public class ChannelFutureClientDemo {
    public static void main(String[] args) throws InterruptedException {
        EventLoopGroup worker = new NioEventLoopGroup();
        Bootstrap bootstrap = new Bootstrap();
        bootstrap.group(worker).channel(NioSocketChannel.class)
                .handler(new ChannelInitializer<NioSocketChannel>() {
                    @Override
                    protected void initChannel(NioSocketChannel channel) throws Exception {
                        channel.pipeline().addLast(new ChannelInboundHandlerAdapter());
                    }
                });
        ChannelFuture channelFuture = bootstrap.connect("127.0.0.1", 8080);
        System.out.println(channelFuture.channel());
        //channelFuture.sync();
        //System.out.println(channelFuture.channel());
        channelFuture.addListener((ChannelFutureListener) future -> {
            System.out.println(future.channel());}
        );
    }
}
